﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace SalePoints.Web.Models
{
	public class CacheServices
	{
		private static Cache _chacher = HttpContext.Current.Cache;
		public static object Get(string key) {
			return _chacher.Get(key);
		}
		public static void Add(string key, object obj,double expiredMinutes,bool slidingCache) {
			if (slidingCache)
			{
				_chacher.Add(key, obj, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(expiredMinutes), CacheItemPriority.Normal, null);
			}
			else {
				_chacher.Add(key, obj, null, DateTime.Now.AddMinutes(expiredMinutes), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
			}
		}
		public static void Add(string key, object obj, DateTime obsoluteExpiration) {
			_chacher.Add(key, obj, null, obsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
		}
		public static void Remove(string key) {
			try
			{
				_chacher.Remove(key);
			}
			catch { }
		}
	}
}
